package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.UserInfo;
import com.sc.nft.entity.vo.CollectionTransferDetailsVO;
import com.sc.nft.entity.vo.CollectionTransferSimpleListVO;
import com.sc.nft.mapper.CollectionGiftLogMapper;
import com.sc.nft.entity.CollectionGiftLog;
import com.sc.nft.service.CollectionGiftLogService;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

/**
 * 权益道具赠送日志(CollectionGiftLog)表Dao层
 *
 * @author 王伟成
 * @since 2024-03-16 15:19:39
 */
@Slf4j
@Repository
public class CollectionGiftLogDao extends ServiceImpl<CollectionGiftLogMapper, CollectionGiftLog> {

    public IPage<CollectionTransferSimpleListVO> collectionTransferSimpleList(UserInfo userInfo, Page mp) {
        LambdaQueryWrapper<CollectionGiftLog> wrapper = Wrappers.lambdaQuery();
        wrapper.select(CollectionGiftLog::getCollectionId,CollectionGiftLog::getTitle,CollectionGiftLog::getCreateTime,CollectionGiftLog::getId);
        wrapper.eq(CollectionGiftLog::getGiftUserId,userInfo.getId());
        wrapper.orderByDesc(CollectionGiftLog::getId);
        Page<CollectionGiftLog> page = page(mp,wrapper);
        IPage<CollectionTransferSimpleListVO> result = page.convert(v -> {
            CollectionTransferSimpleListVO vo = new CollectionTransferSimpleListVO();
            vo.setId(v.getId());
            vo.setTitle(v.getTitle());
            vo.setCreateTime(v.getCreateTime());
            return vo;
        });
        return result;
    }
    public CollectionTransferDetailsVO getByIdDetails(Long id) {
      return baseMapper.getByIdDetails(id);
    }
}
